package com.xxgc.vfc.modules.consumer.score.controller;

import cn.dev33.satoken.annotation.*;
import cn.dev33.satoken.stp.StpUtil;
import com.xxgc.vfc.api.result.Result;
import com.xxgc.vfc.api.service.IScoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: Sjy
 * @Date :2023/10/20 - 10 - 20 - 14:41
 * 以后接口起名  = 服务名 + 类名
 */
@SaCheckLogin
@Api(tags = "分数接口")
@RestController
@RequestMapping("/score")
public class ScoreController {

    @DubboReference(
            interfaceClass = IScoreService.class,
            version = "0.0.1",
            check = false)
    private IScoreService iScoreService;

    //可以是lck角色又可以说lpl角色
    @SaCheckPermission(orRole = {"lck","lpl"})
    @ApiOperation(value = "查询分数")
    @GetMapping("/getMessage")
    public Result getMessage(){
        Integer scoreByUserIdCard = iScoreService.getScoreByUserIdCard("1");
        return Result.ok("分数："+scoreByUserIdCard).msg("Hello Spring Cloud Alibaba");
    }

    @SaCheckRole("lpl")
    @ApiOperation(value = "获取在LPL中的胜场")
    @GetMapping("/getLPLWins")
    public Result getLPLWins(){
        return Result.ok("胜利了100场");
    }

    @SaCheckRole("lck")//角色校验
    @ApiOperation(value = "获取在LCK中的胜场")
    @GetMapping("/getLCKWins")
    public Result getLCKWins(){
        return Result.ok("胜利了1场");
    }

    //拥有score:starting权限或者score:all权限都可以调用
    @SaCheckPermission(value = {"score:starting", "score:all"}, mode = SaMode.OR)
    @ApiOperation(value = "查询自己是否是首发")
    @GetMapping("/starting")
    public Result starting(){
        return Result.ok().msg("你是首发队员");
    }

    //忽略权限
    @SaIgnore
    @ApiOperation(value = "获取联盟公告")
    @GetMapping("/getNotice")
    public Result getNotice(){
        return Result.ok().msg("2023年11月19日，16:00英雄联盟S13全球总决赛。");
    }

    //踢人下线 1725427932561924098
    @SaCheckRole("admin")
    @ApiOperation(value = "踢人下线")
    @PostMapping("/kickout")
    public Result kickout(String userId){
        StpUtil.logout(userId);
        StpUtil.kickout(userId);
        return Result.ok("用户已下线");
    }
}
